/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#pragma once

#include <chrono>
#include <time.h>
#include <基本类型.h>



Inline int64 time_开始计时() {
	return clock();
}

Inline float32 time_当前时间差(int64& st) {
	int64 et = clock();
	float64 gdur = (float64)(et - st);
	gdur = (gdur * 1000 / CLOCKS_PER_SEC);
	st = et;
	return gdur;
}




class C_计时 {
	uint32									m_累计次数;
	uint32									m_累计计数;

	std::chrono::steady_clock::time_point	m_开始时间;

	float64									m_累计时间;
	std::string								m_标签;

public:
	C_计时(std::string 标签, uint32 累计次数 = 1) {
		m_累计次数 = 累计次数;
		m_累计计数 = 0;
		m_标签 = 标签;

		begin();
	}
	void begin() {
		m_开始时间 = std::chrono::high_resolution_clock::now();
	}
	uint32 end() {
		auto 结束时间 = std::chrono::high_resolution_clock::now();
		//auto 时间差 = std::chrono::duration_cast<std::chrono::microseconds>(结束时间 - m_开始时间).count();
		auto 时间差 = std::chrono::duration_cast<std::chrono::milliseconds>(结束时间 - m_开始时间).count();
		//auto 时间差 = std::chrono::duration_cast<std::chrono::seconds>(结束时间 - m_开始时间).count();

		m_累计时间 += 时间差;
		++m_累计计数;


		if (m_累计计数 >= m_累计次数) {
			std::cout<<m_标签<<" **************** 时间差:"<< m_累计时间 / m_累计次数 <<" 毫秒 ********************\r\n";
			m_累计计数 = 0;
			m_累计时间 = 0;
		}
		return 时间差;
		
	}
};










